package leap;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;

import util.Point;
import util.Vector;

public class TestingGround {
	
	static Set<Point> pointArray = new HashSet<Point>();;

	public static void main(String[] args) {
		
		Random rand = new Random();
		for(int i = 0; i < 100; i++) {
			pointArray.add(new Point(250*rand.nextFloat(), 250*rand.nextFloat(), 250*rand.nextFloat()));
		}
		
		/*---------------*/
		try {
			Display.setDisplayMode(new DisplayMode(250, 250));
			Display.create();
		} catch (LWJGLException e) {
			e.printStackTrace();
			System.exit(0);
		}

		initGL();

		while (!Display.isCloseRequested()) {
			
			if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
				renderGL();
			}
			if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
				Point origin = new Point(0,0,0);
				Vector tempVector;
				for(Point p : pointArray) {
					tempVector = p.subtractPointFromPoint(origin);
					p.setPointToPoint(origin);
					p.addVectorToPoint(tempVector.scale(0.99f));
				}
			}			
			if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
				Point origin = new Point(0,0,0);
				Vector tempVector;
				for(Point p : pointArray) {
					tempVector = p.subtractPointFromPoint(origin);
					p.setPointToPoint(origin);
					p.addVectorToPoint(tempVector.scale(1.01f));
				}
			}
			if (Keyboard.isKeyDown(Keyboard.KEY_R)) {
				Point origin = new Point(100,100,100);
				Vector tempVector;
				for(Point p : pointArray) {
					tempVector = p.subtractPointFromPoint(origin);
					p.setPointToPoint(origin);
					p.addVectorToPoint(tempVector.rotateXY(1/*degree*/));
				}
			}
			
			renderGL();
			Display.update();
			Display.sync(60);
		}
	
		Display.destroy();
	}
	
	private static void initGL() {
		GL11.glMatrixMode(GL11.GL_PROJECTION);
		GL11.glLoadIdentity();
		GL11.glOrtho(0, 250, 0, 250, 1, -1);
		GL11.glMatrixMode(GL11.GL_MODELVIEW); // init OpenGL
	}

	static void renderGL() {
		// Clear The Screen And The Depth Buffer
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

		// R,G,B,A Set The Color One Time Only
		GL11.glColor3f(1f, 1f, 1f);
		
		//new Point(10, 100, 100).drawPoint();
		for(Point p : pointArray) {
			p.draw();
		}
	}
}
